home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / cg.lha / cg / src / c2.puma < prev    next >
Text File  |  1992-11-24  |  19KB  |  694 lines

  1. /* Ich, Doktor Josef Grosch, Informatiker, 28.6.1990 */
  2.  
  3. TRAFO TreeC2
  4. TREE Tree
  5. PUBLIC TreeIO GetIterator
  6.  
  7. EXPORT    {
  8. FROM Positions    IMPORT tPosition;
  9.  
  10. VAR Iterator    : Tree.tTree;
  11.  
  12. PROCEDURE WriteLine (Line: tPosition);
  13. }
  14.  
  15. GLOBAL    {
  16.  
  17. FROM IO        IMPORT WriteS, WriteNl;
  18. FROM Sets    IMPORT IsElement;
  19. FROM Idents    IMPORT tIdent;
  20. FROM Positions    IMPORT tPosition;
  21.  
  22. FROM Tree    IMPORT
  23.    NoTree    , tTree        , Options    , ClassCount    ,
  24.    f        , WI    , WN    , iInteger    , itTree    ,
  25.    iNoTree    , iModule    , iMain        , HasChildren    ,
  26.    HasAttributes, NoCodeAttr    , NoCodeClass    ,
  27.    ForallClasses, ForallAttributes, Reverse    ;
  28.  
  29. VAR
  30.    iClassName    : tIdent;
  31.    RevChild    : tTree;
  32.  
  33. PROCEDURE WriteLine (Line: tPosition);
  34.    BEGIN
  35.       IF Line.Line # 0 THEN
  36.      IF IsElement (ORD ('6'), Options) THEN
  37.         !# line ! WN (Line.Line); @ "@ WI (Line.File); @"@
  38.      ELSE
  39.         !/* line ! WN (Line.Line); @ "@ WI (Line.File); @" */@
  40.      END;
  41.       END;
  42.    END WriteLine;
  43. }
  44.  
  45. PROCEDURE TreeIO (t: Tree)
  46.  
  47. Ag (..) :- {
  48.     !typedef ! WI (itTree); ! * yyPtrtTree;!
  49.     !!
  50.     !static FILE * yyf;!
  51.     !!
  52.       IF IsElement (ORD (','), Options) THEN
  53.     !static void yyMark!
  54.     !# if defined __STDC__ | defined __cplusplus!
  55.     ! (register ! WI (itTree); ! yyt)!
  56.     !# else!
  57.     ! (yyt) register ! WI (itTree); ! yyt;!
  58.     !# endif!
  59.     !{!
  60.     ! for (;;) {!
  61.     !  if (yyt == ! WI (iNoTree); ! || ++ yyt->yyHead.yyMark > 1) return;!
  62.     !!
  63.     !  switch (yyt->Kind) {!
  64.     ForallClasses (Classes, Mark);
  65.     !  default: return;!
  66.     !  }!
  67.     ! }!
  68.     !}!
  69.     !!
  70.       END;
  71.       IF IsElement (ORD (';'), Options) THEN
  72.         !# define yyInitTreeStoreSize 32!
  73.     !# define yyMapToTree(yyLabel) yyTreeStorePtr [yyLabel]!
  74.     !!
  75.         !static unsigned long yyTreeStoreSize = yyInitTreeStoreSize;!
  76.         !static ! WI (itTree); ! yyTreeStore [yyInitTreeStoreSize];!
  77.         !static ! WI (itTree); ! * yyTreeStorePtr = yyTreeStore;!
  78.     !static int yyLabelCount;!
  79.     !static short yyRecursionLevel = 0;!
  80.     !!
  81.     !static ! WI (iMain); !_tLabel yyMapToLabel!
  82.     !# if defined __STDC__ | defined __cplusplus!
  83.     ! (! WI (itTree); ! yyt)!
  84.     !# else!
  85.     ! (yyt) ! WI (itTree); ! yyt;!
  86.     !# endif!
  87.     !{!
  88.     ! register int yyi;!
  89.     ! for (yyi = 1; yyi <= yyLabelCount; yyi ++) if (yyTreeStorePtr [yyi] == yyt) return yyi;!
  90.     ! if (++ yyLabelCount == yyTreeStoreSize)!
  91.     !  ExtendArray ((char * *) & yyTreeStorePtr, & yyTreeStoreSize, sizeof (! WI (itTree); !));!
  92.     ! yyTreeStorePtr [yyLabelCount] = yyt;!
  93.     ! return yyLabelCount;!
  94.     !}!
  95.     !!
  96.       END;
  97.       IF IsElement (ORD ('w'), Options) OR
  98.      IsElement (ORD ('o'), Options) THEN
  99.     !static void yyWrite! WI (iModule); ! ();!
  100.     !!
  101.     !static void yyWriteNl () { (void) putc ('\n', yyf); }!
  102.     !!
  103.     !static void yyWriteSelector!
  104.     !# if defined __STDC__ | defined __cplusplus!
  105.     ! (char * yys)!
  106.     !# else!
  107.     ! (yys) char * yys;!
  108.     !# endif!
  109.     !{!
  110.     ! register int yyi = 16 - strlen (yys);!
  111.     @ (void) fputs (yys, yyf);@
  112.     ! while (yyi -- > 0) (void) putc (' ', yyf);!
  113.     @ (void) fputs (" = ", yyf);@
  114.     !}!
  115.     !!
  116.     !static void yyWriteHex!
  117.     !# if defined __STDC__ | defined __cplusplus!
  118.     ! (unsigned char * yyx, int yysize)!
  119.     !# else!
  120.     ! (yyx, yysize) unsigned char * yyx; int yysize;!
  121.     !# endif!
  122.     @{ register int yyi; for (yyi = 0; yyi < yysize; yyi ++) (void) fprintf (yyf, "%02x ", yyx [yyi]); }@
  123.     !!
  124.       END;
  125.       IF IsElement (ORD ('o'), Options) THEN
  126.     !static void yyWriteAdr!
  127.     !# if defined __STDC__ | defined __cplusplus!
  128.     ! (! WI (itTree); ! yyt)!
  129.     !# else!
  130.     ! (yyt) ! WI (itTree); ! yyt;!
  131.     !# endif!
  132.     !{!
  133.     ! if (yyt == ! WI (iNoTree); @) (void) fputs ("@ WI (iNoTree); @", yyf);@
  134.     ! else yyWriteHex ((unsigned char *) & yyt, sizeof (yyt));!
  135.     ! yyWriteNl ();!
  136.     !}!
  137.     !!
  138.     ForallClasses (Classes, WriteNode);
  139.     !void Write! WI (iModule); !Node!
  140.     !# if defined __STDC__ | defined __cplusplus!
  141.     ! (FILE * yyyf, ! WI (itTree); ! yyt)!
  142.     !# else!
  143.     ! (yyyf, yyt) FILE * yyyf; ! WI (itTree); ! yyt;!
  144.     !# endif!
  145.     !{!
  146.     ! yyf = yyyf;!
  147.     ! if (yyt == ! WI (iNoTree); @) { (void) fputs ("@ WI (iNoTree); @\n", yyf); return; }@
  148.     !!
  149.     ! switch (yyt->Kind) {!
  150.     ForallClasses (Classes, WriteNodeName);
  151.     ! default: ;!
  152.     ! }!
  153.     !}!
  154.     !!
  155.       END;
  156.       IF IsElement (ORD ('w'), Options) THEN
  157.     !static short yyIndentLevel;!
  158.     !!
  159.     !void Write! WI (iModule); !!
  160.     !# if defined __STDC__ | defined __cplusplus!
  161.     ! (FILE * yyyf, ! WI (itTree); ! yyt)!
  162.     !# else!
  163.     ! (yyyf, yyt) FILE * yyyf; ! WI (itTree); ! yyt;!
  164.     !# endif!
  165.     !{!
  166.     ! short yySaveLevel = yyIndentLevel;!
  167.     ! yyf = yyyf;!
  168.     ! if (yyRecursionLevel ++ == 0) yyLabelCount = 0;!
  169.     ! yyMark (yyt);!
  170.     ! yyIndentLevel = 0;!
  171.     ! yyWrite! WI (iModule); ! (yyt);!
  172.     ! yyIndentLevel = yySaveLevel;!
  173.     ! yyRecursionLevel --;!
  174.     !}!
  175.     !!
  176.     !static void yyIndentSelector!
  177.     !# if defined __STDC__ | defined __cplusplus!
  178.     ! (char * yys)!
  179.     !# else!
  180.     ! (yys) char * yys;!
  181.     !# endif!
  182.     !{!
  183.     ! register int yyi;!
  184.     ! for (yyi = 1; yyi <= yyIndentLevel; yyi ++) (void) putc (' ', yyf);!
  185.     ! yyWriteSelector (yys);!
  186.     !}!
  187.     !!
  188.     !static void yyIndentSelectorTree!
  189.     !# if defined __STDC__ | defined __cplusplus!
  190.     ! (char * yys, ! WI (itTree); ! yyt)!
  191.     !# else!
  192.     ! (yys, yyt) char * yys; ! WI (itTree); ! yyt;!
  193.     !# endif!
  194.     !{ yyIndentSelector (yys); write! WI (itTree); ! (yyt) }!
  195.     !!
  196.     ForallClasses (Classes, WriteAttributes);
  197.     !static void yyWrite! WI (iModule); !!
  198.     !# if defined __STDC__ | defined __cplusplus!
  199.     ! (! WI (itTree); ! yyt)!
  200.     !# else!
  201.     ! (yyt) ! WI (itTree); ! yyt;!
  202.     !# endif!
  203.     !{ unsigned short yyLevel = yyIndentLevel;!
  204.     ! for (;;) {!
  205.     !  if (yyt == ! WI (iNoTree); @) { (void) fputs (" @ WI (iNoTree); @\n", yyf); goto yyExit;@
  206.     @  } else if (yyt->yyHead.yyMark == 0) { (void) fprintf (yyf, "^%d\n", yyMapToLabel (yyt)); goto yyExit;@
  207.     !  } else if (yyt->yyHead.yyMark > 1) {!
  208.     !   register int yyi;!
  209.     @   (void) fprintf (yyf, "\n%06d:", yyMapToLabel (yyt));@
  210.     !   for (yyi = 8; yyi <= yyIndentLevel; yyi ++) (void) putc (' ', yyf);!
  211.     !  } else (void) putc (' ', yyf);!
  212.     !  yyt->yyHead.yyMark = 0;!
  213.     !  yyIndentLevel += 2;!
  214.     !!
  215.     !  switch (yyt->Kind) {!
  216.     ForallClasses (Classes, WriteClassName);
  217.     !  default: goto yyExit;!
  218.     !  }!
  219.     ! }!
  220.     !yyExit:!
  221.     ! yyIndentLevel = yyLevel;!
  222.     !}!
  223.     !!
  224.       END;
  225.       IF IsElement (ORD ('r'), Options) THEN
  226.     !static tIdent yyKindToIdent [! WN (ClassCount); ! + 1];!
  227.     !static bool yyIsInitialized = false;!
  228.     !!
  229.     !static short yyMapToKind!
  230.     !# if defined __STDC__ | defined __cplusplus!
  231.     ! (char * yys)!
  232.     !# else!
  233.     ! (yys) char * yys;!
  234.     !# endif!
  235.     !{!
  236.     ! register int yyk;!
  237.     ! register tIdent yyi = MakeIdent ((tString) yys, strlen (yys));!
  238.     ! for (yyk = 0; yyk <= ! WN (ClassCount); !; yyk ++) {!
  239.     !  if (yyKindToIdent [yyk] == yyi) return yyk;!
  240.     ! }!
  241.     ! return 0;!
  242.     !}!
  243.     !!
  244.     @static void yyReadNl () { (void) fscanf (yyf, "\n"); }@
  245.     !!
  246.     !static tIdent yyReadIdent ()!
  247.     !{!
  248.     ! char yys [256];!
  249.     @ (void) fscanf (yyf, "%s", yys);@
  250.     ! return MakeIdent ((tString) yys, strlen (yys));!
  251.     !}!
  252.     !!
  253.     !static void yyReadHex!
  254.     !# if defined __STDC__ | defined __cplusplus!
  255.     ! (unsigned char * yyx, int yysize)!
  256.     !# else!
  257.     ! (yyx, yysize) unsigned char * yyx; int yysize;!
  258.     !# endif!
  259.     !{!
  260.     ! register int yyi; int yyk;!
  261.     @ for (yyi = 0; yyi < yysize; yyi ++) { (void) fscanf (yyf, "%x ", & yyk); yyx [yyi] = yyk; }@
  262.     !}!
  263.     !!
  264.     @static void yySkip () { (void) fscanf (yyf, " %*s =%*c"); }@
  265.     !!
  266.     !static void yyRead! WI (iModule); !!
  267.     !# if defined __STDC__ | defined __cplusplus!
  268.     ! (yyPtrtTree yyt)!
  269.     !# else!
  270.     ! (yyt) yyPtrtTree yyt;!
  271.     !# endif!
  272.     !{!
  273.     ! static ! WI (iMain); !_tLabel yyLabel;!
  274.     ! static ! WI (iMain); !_tKind yyKind;!
  275.     ! static char yys [256];!
  276.     ! for (;;) {!
  277.     !  switch (getc (yyf)) {!
  278.     !  case '^':!@ (void) fscanf (yyf, "%hd\n", & yyLabel); * yyt = yyMapToTree (yyLabel); return;@
  279.     !  case '\n': case '0':!@ (void) fscanf (yyf, "%hd%*c %s\n", & yyLabel, yys);@
  280.     !   yyKind = yyMapToKind (yys); * yyt = Make! WI (iMain); ! (yyKind);!
  281.     @   if (yyLabel != yyMapToLabel (* yyt)) { (void) fputs ("@ WI (iModule);
  282.     !: error in Read! WI (iModule); @\n", stderr); @ WI (iMain); !_Exit (); } break;!
  283.     !  default: ;!
  284.     @   (void) fscanf (yyf, "%s", yys);@
  285.     !   yyKind = yyMapToKind (yys);!
  286.     !   if (yyKind == 0) { * yyt = ! WI (iNoTree); !; return; }!
  287.     !   * yyt = Make! WI (iMain); ! (yyKind);!
  288.     !  }!
  289.     !!
  290.     !  switch (yyKind) {!
  291.     ForallClasses (Classes, ReadAttributes);
  292.     !  default: return;!
  293.     !  }!
  294.     ! }!
  295.     !}!
  296.     !!
  297.     WI (itTree); ! Read! WI (iModule); !!
  298.     !# if defined __STDC__ | defined __cplusplus!
  299.     ! (FILE * yyyf)!
  300.     !# else!
  301.     ! (yyyf) FILE * yyyf;!
  302.     !# endif!
  303.     !{!
  304.     ! ! WI (itTree); ! yyt;!
  305.     ! yyf = yyyf;!
  306.     ! if (yyRecursionLevel ++ == 0) yyLabelCount = 0;!
  307.     @ if (! yyIsInitialized) {@
  308.     !  register int yyi;!
  309.     !  for (yyi = 0; yyi <= ! WN (ClassCount); !; yyi ++)!
  310.     !   yyKindToIdent [yyi] = MakeIdent ((tString) ! WI (iMain); !_NodeName [yyi], strlen (! WI (iMain); !_NodeName [yyi]));!
  311.     !  yyIsInitialized = true;!
  312.     ! }!
  313.     ! yyRead! WI (iModule); ! (& yyt);!
  314.     ! yyRecursionLevel --;!
  315.     ! return yyt;!
  316.     !}!
  317.     !!
  318.       END;
  319.     !# define yyNil    0374!
  320.     !# define yyNoLabel    0375!
  321.     !# define yyLabelDef    0376!
  322.     !# define yyLabelUse    0377!
  323.     !!
  324.       IF IsElement (ORD ('p'), Options) THEN
  325.     !static void yyPut!
  326.     !# if defined __STDC__ | defined __cplusplus!
  327.     ! (char * yyx, int yysize)!
  328.     !# else!
  329.     ! (yyx, yysize) char * yyx; int yysize;!
  330.     !# endif!
  331.     !{ (void) fwrite (yyx, 1, yysize, yyf); }!
  332.     !!
  333.     !static void yyPutIdent!
  334.     !# if defined __STDC__ | defined __cplusplus!
  335.     ! (tIdent yyi)!
  336.     !# else!
  337.     ! (yyi) tIdent yyi;!
  338.     !# endif!
  339.     !{!
  340.     ! char yys [256];!
  341.     ! GetString (yyi, (tString) yys);!
  342.     @ (void) fprintf (yyf, "%s\n", yys);@
  343.     !}!
  344.     !!
  345.     !static void yyPut! WI (iModule); !!
  346.     !# if defined __STDC__ | defined __cplusplus!
  347.     ! (! WI (itTree); ! yyt)!
  348.     !# else!
  349.     ! (yyt) ! WI (itTree); ! yyt;!
  350.     !# endif!
  351.     !{!
  352.     ! static ! WI (iMain); !_tLabel yyLabel;!
  353.     ! for (;;) {!
  354.     !  if (yyt == ! WI (iNoTree); !) {!
  355.     !   (void) putc (yyNil, yyf); return;!
  356.     !  } else if (yyt->yyHead.yyMark == 0) {!
  357.     !   (void) putc (yyLabelUse, yyf); yyLabel = yyMapToLabel (yyt); yyPut ((char *) & yyLabel, sizeof (yyLabel)); return;!
  358.     !  } else if (yyt->yyHead.yyMark > 1) {!
  359.     !   (void) putc (yyLabelDef, yyf); yyLabel = yyMapToLabel (yyt); yyPut ((char *) & yyLabel, sizeof (yyLabel));!
  360.     IF ClassCount > 251 THEN
  361.     !   yyPut ((char *) & yyt->Kind, sizeof (! WI (iMain); !_tKind));!
  362.     !  } else if (yyt->Kind > 251) {!
  363.     !   (void) putc (yyNoLabel, yyf); yyPut ((char *) & yyt->Kind, sizeof (! WI (iMain); !_tKind));!
  364.     ELSE
  365.     !   (void) putc ((char) yyt->Kind, yyf);!
  366.     END;
  367.     !  } else {!
  368.     !   (void) putc ((char) yyt->Kind, yyf);!
  369.     !  }!
  370.     !  yyt->yyHead.yyMark = 0;!
  371.     !!
  372.     !  switch (yyt->Kind) {!
  373.     ForallClasses (Classes, PutAttributes);
  374.     !  default: return;!
  375.     !  }!
  376.     ! }!
  377.     !}!
  378.     !!
  379.     !void Put! WI (iModule); !!
  380.     !# if defined __STDC__ | defined __cplusplus!
  381.     ! (FILE * yyyf, ! WI (itTree); ! yyt)!
  382.     !# else!
  383.     ! (yyyf, yyt) FILE * yyyf; ! WI (itTree); ! yyt;!
  384.     !# endif!
  385.     !{!
  386.     ! yyf = yyyf;!
  387.     ! if (yyRecursionLevel ++ == 0) yyLabelCount = 0;!
  388.     ! yyMark (yyt);!
  389.     ! yyPut! WI (iModule); ! (yyt);!
  390.     ! yyRecursionLevel --;!
  391.     !}!
  392.     !!
  393.       END;
  394.       IF IsElement (ORD ('g'), Options) THEN
  395.     !static void yyGet!
  396.     !# if defined __STDC__ | defined __cplusplus!
  397.     ! (char * yyx, int yysize)!
  398.     !# else!
  399.     ! (yyx, yysize) char * yyx; int yysize;!
  400.     !# endif!
  401.     !{ (void) fread (yyx, 1, yysize, yyf); }!
  402.     !!
  403.     !static void yyGetIdent!
  404.     !# if defined __STDC__ | defined __cplusplus!
  405.     ! (tIdent * yyi)!
  406.     !# else!
  407.     ! (yyi) tIdent * yyi;!
  408.     !# endif!
  409.     !{!
  410.     ! char yys [256];!
  411.     @ (void) fscanf (yyf, "%s%*c", yys);@
  412.     ! * yyi = MakeIdent ((tString) yys, strlen (yys));!
  413.     !}!
  414.     !!
  415.     !static void yyGet! WI (iModule); !!
  416.     !# if defined __STDC__ | defined __cplusplus!
  417.     ! (yyPtrtTree yyt)!
  418.     !# else!
  419.     ! (yyt) yyPtrtTree yyt;!
  420.     !# endif!
  421.     !{!
  422.     ! static ! WI (iMain); !_tLabel yyLabel;!
  423.     ! static ! WI (iMain); !_tKind yyKind;!
  424.     ! for (;;) {!
  425.     !  switch (yyKind = getc (yyf)) {!
  426.     !  case yyNil        : * yyt = ! WI (iNoTree); !; return;!
  427.     !  case yyLabelUse    : yyGet ((char *) & yyLabel, sizeof (yyLabel));!
  428.     !   * yyt = yyMapToTree (yyLabel); return;!
  429.     !  case yyLabelDef    : yyGet ((char *) & yyLabel, sizeof (yyLabel));!
  430.     IF ClassCount > 251 THEN
  431.     !   yyGet ((char *) & yyKind, sizeof (yyKind));!
  432.     ELSE
  433.     !   yyKind = getc (yyf);! 
  434.     END;
  435.     !   * yyt = Make! WI (iMain); ! (yyKind);!
  436.     @   if (yyLabel != yyMapToLabel (* yyt)) { (void) fputs ("@ WI (iModule);
  437.     !: error in Get! WI (iModule); @\n", stderr); @ WI (iMain); !_Exit (); } break;!
  438.     IF ClassCount > 251 THEN
  439.     !  case yyNoLabel    : yyGet ((char *) & yyKind, sizeof (yyKind));!
  440.     !   * yyt = Make! WI (iMain); ! (yyKind); break;!
  441.     END;
  442.     !  default    : * yyt = Make! WI (iMain); ! (yyKind);!
  443.     !  }!
  444.     !!
  445.     !  switch (yyKind) {!
  446.     ForallClasses (Classes, GetAttributes);
  447.     !  default: return;!
  448.     !  }!
  449.     ! }!
  450.     !}!
  451.     !!
  452.     WI (itTree); ! Get! WI (iModule); !!
  453.     !# if defined __STDC__ | defined __cplusplus!
  454.     ! (FILE * yyyf)!
  455.     !# else!
  456.     ! (yyyf) FILE * yyyf;!
  457.     !# endif!
  458.     !{!
  459.     ! ! WI (itTree); ! yyt;!
  460.     ! yyf = yyyf;!
  461.     ! if (yyRecursionLevel ++ == 0) yyLabelCount = 0;!
  462.     ! yyGet! WI (iModule); ! (& yyt);!
  463.     ! yyRecursionLevel --;!
  464.     ! return yyt;!
  465.     !}!
  466.     !!
  467.       END;
  468. }; .
  469.  
  470.  
  471. PROCEDURE WriteNodeName (t: Tree)
  472.  
  473. Class (..) :- {
  474.     IF (NoCodeClass * Properties) = {} THEN
  475.        !case k! WI (Name); !: (void) fputs (! WI (iMain); !_NodeName [k! WI (Name);
  476.        !], yyf); (void) fputc ('\n', yyf);!
  477.        IF ({HasChildren, HasAttributes} * Properties) # {} THEN
  478.           ! yWriteNode! WI (Name); ! (yyt);! 
  479.        END;
  480.        ! break;!
  481.     END;
  482. }; .
  483.  
  484.  
  485. PROCEDURE WriteNode (t: Tree)
  486.  
  487. Class (..) :- {
  488.     IF ((NoCodeClass * Properties) = {}) AND
  489.        (({HasChildren, HasAttributes} * Properties) # {}) THEN
  490.        !static void yWriteNode! WI (Name); !!
  491.        !# if defined __STDC__ | defined __cplusplus!
  492.        ! (! WI (itTree); ! yyt)!
  493.        !# else!
  494.        ! (yyt) ! WI (itTree); ! yyt;!
  495.        !# endif!
  496.        !{!
  497.        IF (BaseClass^.Kind = Tree.Class) AND        (* NOT Top ? *)
  498.           (({HasChildren, HasAttributes} * BaseClass^.Class.Properties) # {}) THEN
  499.        ! yWriteNode! WI (BaseClass^.Class.Name); ! (yyt); !
  500.        END;
  501.        iClassName := Name;
  502.        ForallAttributes (Attributes, WriteNode);
  503.        !}!
  504.        !!
  505.     END;
  506. }; .
  507. Child (..) :- {
  508.     @ yyWriteSelector ("@ WI (Name); @");@ 
  509.     ! yyWriteAdr (yyt->! WI (iClassName); !.! WI (Name); !);!
  510. }; .
  511. Attribute (..) :- {
  512.     IF (NoCodeAttr * Properties) = {} THEN 
  513.        @ yyWriteSelector ("@ WI (Name); @"); write@ WI (Type);
  514.        ! (yyt->! WI (iClassName); !.! WI (Name); !) yyWriteNl ();!
  515.     END;
  516. }; .
  517.  
  518.  
  519. PROCEDURE Mark (t: Tree)
  520.  
  521. Class (..) :- {
  522.     IF ((NoCodeClass * Properties) = {}) AND (HasChildren IN Properties) THEN
  523.        !case k! WI (Name); !:!
  524.        GetIterator (t);
  525.        iClassName := Name;
  526.        ForallAttributes (t, Mark);
  527.        IF Iterator = NoTree THEN
  528.           !return;!
  529.        ELSE
  530.           !yyt = yyt->! WI (iClassName); !.! WI (Iterator^.Child.Name); !; break;!
  531.        END;
  532.     END;
  533. }; .
  534. Child (..) :- {
  535.     IF t # Iterator THEN
  536.        !yyMark (yyt->! WI (iClassName); !.! WI (Name); !);!
  537.     END;
  538. }; .
  539.  
  540.  
  541. PROCEDURE WriteClassName (t: Tree)
  542.  
  543. Class (..) :- {
  544.     IF (NoCodeClass * Properties) = {} THEN
  545.        !case k! WI (Name); !: ! 
  546.        IF ({HasChildren, HasAttributes} * Properties) # {} THEN
  547.           !yWrite! WI (Name); ! (yyt); ! 
  548.           GetIterator (t);
  549.           IF Iterator = NoTree THEN
  550.          !goto yyExit;!
  551.           ELSE
  552.          @yyIndentSelector ("@ WI (Iterator^.Child.Name); @"); @ 
  553.          !yyt = yyt->! WI (Name); !.! WI (Iterator^.Child.Name); !; break;!
  554.           END;
  555.        ELSE
  556.           !(void) fputs (! WI (iMain); !_NodeName [k! WI (Name);
  557.           !], yyf); (void) fputc ('\n', yyf); goto yyExit;!
  558.        END;
  559.     END;
  560. }; .
  561.  
  562.  
  563. PROCEDURE WriteAttributes (t: Tree)
  564.  
  565. Class (..) :- {
  566.     IF ((NoCodeClass * Properties) = {}) AND
  567.        (({HasChildren, HasAttributes} * Properties) # {}) THEN
  568.        !static void yWrite! WI (Name); !!
  569.        !# if defined __STDC__ | defined __cplusplus!
  570.        ! (! WI (itTree); ! yyt)!
  571.        !# else!
  572.        ! (yyt) ! WI (itTree); ! yyt;!
  573.        !# endif!
  574.        !{!
  575.        ! (void) fputs (! WI (iMain); !_NodeName [k! WI (Name);
  576.        !], yyf); (void) fputc ('\n', yyf);!
  577.        GetIterator (t);
  578.        iClassName := Name;
  579.        ForallAttributes (t, WriteAttributes);
  580.        !}!
  581.        !!
  582.     END;
  583. }; .
  584. Child (..) :- {
  585.     IF t # Iterator THEN
  586.        @ yyIndentSelectorTree ("@ WI (Name); @", yyt->@ WI (iClassName); !.! WI (Name); !);!
  587.     END;
  588. }; .
  589. Attribute (..) :- {
  590.     IF (NoCodeAttr * Properties) = {} THEN 
  591.        @ yyIndentSelector ("@ WI (Name); @"); @ 
  592.        !write! WI (Type); ! (yyt->! WI (iClassName); !.! WI (Name); !) yyWriteNl ();!
  593.     END;
  594. }; .
  595.  
  596.  
  597. PROCEDURE ReadAttributes (t: Tree)
  598.  
  599. Class (..) :- {
  600.     IF ((NoCodeClass * Properties) = {}) AND
  601.        (({HasChildren, HasAttributes} * Properties) # {}) THEN
  602.        !case k! WI (Name); !:!
  603.        GetIterator (t);
  604.        iClassName := Name;
  605.        ForallAttributes (t, ReadAttributes);
  606.        IF Iterator = NoTree THEN
  607.           !return;!
  608.        ELSE
  609.           !yySkip (); yyt = & ((* yyt)->! WI (iClassName); !.! WI (Iterator^.Child.Name); !); break;!
  610.        END;
  611.     END;
  612. }; .
  613. Child (..) :- {
  614.     IF t # Iterator THEN
  615.        !yySkip (); read! WI (itTree); ! (& ((* yyt)->! WI (iClassName); !.! WI (Name); !))!
  616.     END;
  617. }; .
  618. Attribute (..) :- {
  619.     IF (NoCodeAttr * Properties) = {} THEN 
  620.        !yySkip (); read! WI (Type); ! ((* yyt)->! WI (iClassName); !.! WI (Name); !) yyReadNl ();!
  621.     END;
  622. }; .
  623.  
  624.  
  625. PROCEDURE PutAttributes (t: Tree)
  626.  
  627. Class (..) :- {
  628.     IF ((NoCodeClass * Properties) = {}) AND
  629.        (({HasChildren, HasAttributes} * Properties) # {}) THEN
  630.        !case k! WI (Name); !:!
  631.        GetIterator (t);
  632.        iClassName := Name;
  633.        ForallAttributes (t, PutAttributes);
  634.        IF Iterator = NoTree THEN
  635.           !return;!
  636.        ELSE
  637.           !yyt = yyt->! WI (iClassName); !.! WI (Iterator^.Child.Name); !; break;!
  638.        END;
  639.     END;
  640. }; .
  641. Child (..) :- {
  642.     IF t # Iterator THEN
  643.        !put! WI (itTree); ! (yyt->! WI (iClassName); !.! WI (Name); !)!
  644.     END;
  645. }; .
  646. Attribute (..) :- {
  647.     IF (NoCodeAttr * Properties) = {} THEN 
  648.        !put! WI (Type); ! (yyt->! WI (iClassName); !.! WI (Name); !)!
  649.     END;
  650. }; .
  651.  
  652.  
  653. PROCEDURE GetAttributes (t: Tree)
  654.  
  655. Class (..) :- {
  656.     IF ((NoCodeClass * Properties) = {}) AND
  657.        (({HasChildren, HasAttributes} * Properties) # {}) THEN
  658.        !case k! WI (Name); !:!
  659.        GetIterator (t);
  660.        iClassName := Name;
  661.        ForallAttributes (t, GetAttributes);
  662.        IF Iterator = NoTree THEN
  663.           !return;!
  664.        ELSE
  665.           !yyt = & ((* yyt)->! WI (iClassName); !.! WI (Iterator^.Child.Name); !); break;!
  666.        END;
  667.     END;
  668. }; .
  669. Child (..) :- {
  670.     IF t # Iterator THEN
  671.        !get! WI (itTree); ! (& ((* yyt)->! WI (iClassName); !.! WI (Name); !))!
  672.     END;
  673. }; .
  674. Attribute (..) :- {
  675.     IF (NoCodeAttr * Properties) = {} THEN 
  676.        !get! WI (Type); ! ((* yyt)->! WI (iClassName); !.! WI (Name); !)!
  677.     END;
  678. }; .
  679.  
  680.  
  681. PROCEDURE GetIterator (t: Tree)
  682.  
  683. Class (..) :- {
  684.     Iterator := NoTree;
  685.     RevChild := NoTree;
  686.     ForallAttributes (t, GetIterator);
  687.     IF RevChild # NoTree THEN Iterator := RevChild; END;
  688. }; .
  689. Child (..) :- {
  690.     Iterator := t;
  691.     IF Reverse IN Properties THEN RevChild := t; END;
  692. }; .
  693.  
  694.